package cn.z2huo.demo.hello.kafka.util;

import cn.hutool.core.net.NetUtil;

import java.util.List;

/**
 * <p>
 *
 * @author z2huo
 */
public final class KafkaConfig {

    /**
     * kafka生产者的配置项前缀(NEW)
     */
    public static final String PRODUCER_PROP_PREFIX = "hello.kafka.producer.";

    /**
     * kafka消费者的配置项前缀
     */
    public static final String CONSUMER_PROP_PREFIX = "hello.kafka.consumer.";

    /**
     * kafka生产者的配置项前缀(兼容)
     */
    public static final String PRODUCER_PROP_LEGACY_PREFIX = "kafka.producer.";

    /**
     * kafka消费者的配置项前缀(兼容)
     */
    public static final String CONSUMER_PROP_LEGACY_PREFIX = "kafka.consumer.";

    /**
     * 放入{@link KafkaConsumerRunnerDao} 的Subscriber实例对应的key生成规则：consumerName:groupId:topiclist
     */
    public static final String subscriberKeyPattern = "%s:%s:%s";

    public static String generateRunnerName(String consumerName, String groupId, List<String> topicList) {
        return String.format(KafkaConfig.subscriberKeyPattern, consumerName, groupId, String.join(",", topicList));
    }

    public static String generateProducerClientId() {
        return "producer" + NetUtil.getLocalHostName();
    }

    public static String generateConsumerClientId() {
        return "consumer" + NetUtil.getLocalHostName();
    }
}
